﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GodReply.ORM
{
    public partial class DbAccessory
    {
        #region Properties
        //public SqlSugarClient Context { get; set; }
        public ConnectionConfig CurrentConnectionConfig { get; set; }
        //public Dictionary<string, object> TempItems { get; set; }
        //public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } }
        //public Guid ContextID { get; set; }
        //public MappingTableList MappingTables = new MappingTableList();
        //public MappingColumnList MappingColumns = new MappingColumnList();
        //public IgnoreColumnList IgnoreColumns = new IgnoreColumnList();
        #endregion

        #region Fields
        // protected ISqlBuilder _SqlBuilder;
        // protected EntityMaintenance _EntityProvider;
        protected IAdo _Ado;
        // protected ILambdaExpressions _LambdaExpressions;
        //  protected IRewritableMethods _RewritableMethods;
        //  protected IDbMaintenance _DbMaintenance;
        //  protected QueryFilterProvider _QueryFilterProvider;
        #endregion

        //#region Create Instance
        //protected ISugarQueryable<T> CreateQueryable<T>() where T : class, new()
        //{
        //    ISugarQueryable<T> result = InstanceFactory.GetQueryable<T>(this.CurrentConnectionConfig);
        //    return CreateQueryable(result);
        //}
        //protected ISugarQueryable<T> CreateQueryable<T>(ISugarQueryable<T> result) where T : class, new()
        //{
        //    var sqlBuilder = InstanceFactory.GetSqlbuilder(CurrentConnectionConfig);
        //    result.Context = this.Context;
        //    result.SqlBuilder = sqlBuilder;
        //    result.SqlBuilder.QueryBuilder = InstanceFactory.GetQueryBuilder(CurrentConnectionConfig);
        //    result.SqlBuilder.QueryBuilder.Builder = sqlBuilder;
        //    result.SqlBuilder.Context = result.SqlBuilder.QueryBuilder.Context = this.Context;
        //    result.SqlBuilder.QueryBuilder.EntityType = typeof(T);
        //    result.SqlBuilder.QueryBuilder.EntityName = typeof(T).Name;
        //    result.SqlBuilder.QueryBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(CurrentConnectionConfig);
        //    return result;
        //}
        //protected InsertableProvider<T> CreateInsertable<T>(T[] insertObjs) where T : class, new()
        //{
        //    var reval = new InsertableProvider<T>();
        //    var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
        //    reval.Context = this.Context;
        //    reval.EntityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
        //    reval.SqlBuilder = sqlBuilder;
        //    reval.InsertObjs = insertObjs;
        //    sqlBuilder.InsertBuilder = reval.InsertBuilder = InstanceFactory.GetInsertBuilder(this.CurrentConnectionConfig);
        //    sqlBuilder.InsertBuilder.Builder = sqlBuilder;
        //    sqlBuilder.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.CurrentConnectionConfig);
        //    sqlBuilder.Context = reval.SqlBuilder.InsertBuilder.Context = this.Context;
        //    reval.Init();
        //    return reval;
        //}
        //protected DeleteableProvider<T> CreateDeleteable<T>() where T : class, new()
        //{
        //    var reval = new DeleteableProvider<T>();
        //    var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
        //    reval.Context = this.Context;
        //    reval.SqlBuilder = sqlBuilder;
        //    sqlBuilder.DeleteBuilder = reval.DeleteBuilder = InstanceFactory.GetDeleteBuilder(this.CurrentConnectionConfig);
        //    sqlBuilder.DeleteBuilder.Builder = sqlBuilder;
        //    sqlBuilder.DeleteBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.CurrentConnectionConfig);
        //    sqlBuilder.Context = reval.SqlBuilder.DeleteBuilder.Context = this.Context;
        //    return reval;
        //}
        //protected UpdateableProvider<T> CreateUpdateable<T>(T[] UpdateObjs) where T : class, new()
        //{
        //    var reval = new UpdateableProvider<T>();
        //    var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
        //    reval.Context = this.Context;
        //    reval.EntityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
        //    reval.SqlBuilder = sqlBuilder;
        //    reval.UpdateObjs = UpdateObjs;
        //    sqlBuilder.UpdateBuilder = reval.UpdateBuilder = InstanceFactory.GetUpdateBuilder(this.CurrentConnectionConfig);
        //    sqlBuilder.UpdateBuilder.Builder = sqlBuilder;
        //    sqlBuilder.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.CurrentConnectionConfig);
        //    sqlBuilder.Context = reval.SqlBuilder.UpdateBuilder.Context = this.Context;
        //    reval.Init();
        //    return reval;
        //}

        //protected void CreateQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable) where T : class, new()
        //{
        //    this.CreateQueryable<T>(queryable);
        //    string shortName = string.Empty;
        //    List<SugarParameter> paramters = new List<SugarParameter>();
        //    queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(queryable.SqlBuilder, joinExpression, ref paramters, ref shortName, types);
        //    queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
        //    if (paramters != null)
        //    {
        //        queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters);
        //    }
        //}
        //protected void CreateEasyQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable) where T : class, new()
        //{
        //    this.CreateQueryable<T>(queryable);
        //    string shortName = string.Empty;
        //    queryable.SqlBuilder.QueryBuilder.EasyJoinInfos = this.GetEasyJoinInfo(joinExpression, ref shortName, queryable.SqlBuilder, types);
        //    queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
        //}
        //#endregion
    }
}
